home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ForCLI / 0Utils13.lha / 0Utils / Examine.c < prev    next >
C/C++ Source or Header  |  1995-03-26  |  4KB  |  177 lines

  1.  
  2. /******************************************************************************
  3.  
  4.     MODULE
  5.     Examine.c
  6.  
  7.     DESCRIPTION
  8.     Examine a certain file or Dir
  9.  
  10.     NOTES
  11.     Kickstart 2.0+ required
  12.     compiles w/ SAS/C v6.51
  13.  
  14.     BUGS
  15.     none known
  16.  
  17.     TODO
  18.  
  19.     EXAMPLES
  20.  
  21.     SEE ALSO
  22.  
  23.     INDEX
  24.  
  25.     HISTORY
  26.     25-03-95 b_noll created
  27.  
  28.     AUTHOR
  29.     Bernd Noll, Brunnenstrasse 55, D-67661 Kaiserslautern
  30.     b_noll@informatik.uni-kl.de
  31.  
  32. ******************************************************************************/
  33.  
  34. /**************************************
  35.         Includes
  36. **************************************/
  37.  
  38. #ifndef   EXEC_LIBRARIES_H
  39. # include <exec/libraries.h>
  40. #endif /* EXEC_LIBRARIES_H */
  41.  
  42. #ifndef   CLIB_EXEC_PROTOS_H
  43. # include <clib/exec_protos.h>
  44. #endif /* CLIB_EXEC_PROTOS_H */
  45.  
  46. #ifndef   DOS_DOS_H
  47. # include <dos/dos.h>
  48. #endif /* DOS_DOS_H */
  49.  
  50. #ifndef   CLIB_DOS_PROTOS_H
  51. # include <clib/dos_protos.h>
  52. #endif /* CLIB_DOS_PROTOS_H */
  53.  
  54. #include <proto/dos.h>
  55. #include <proto/exec.h>
  56.  
  57. /**************************************
  58.      Defines & Structures
  59. **************************************/
  60.  
  61. #ifndef ABSEXECBASE
  62. #define ABSEXECBASE ((struct ExecBase **)4L)
  63. #endif
  64.  
  65. struct _arg {
  66. /* ******************** USER FORMAT ******************** */
  67. #define FORMAT "PATH/A"
  68.  
  69.     STRPTR path;
  70.  
  71. /* ******************** USER FORMAT ******************** */
  72. }; /* struct _argv */
  73.  
  74. #define MAXPATHLEN 256
  75. #define MAXLINELEN 256
  76.  
  77. #define VERSIONPREFIX    "\0$VER: "
  78. #define VERSIONOFFSET    0
  79. #define FORMATPREFIX    "\0$ARG: "
  80. #define FORMATOFFSET    7
  81.  
  82. /**************************************
  83.         Implementation
  84. **************************************/
  85.  
  86. long _main (void)
  87. {
  88.     const char* version = VERSIONPREFIX "Examine 1.0 " __AMIGADATE__  + VERSIONOFFSET;
  89.     long retval = RETURN_FAIL;
  90.     struct ExecBase*SysBase = *ABSEXECBASE;
  91.     struct Library* DOSBase;
  92.  
  93.     if (DOSBase = OpenLibrary (DOSNAME, 37)) {
  94.     struct _arg argv = { 0 };
  95.     APTR   args;
  96.     retval     = RETURN_ERROR;
  97.     if (args = (void*)ReadArgs(FORMATPREFIX FORMAT + FORMATOFFSET, (LONG*)&argv, NULL)) {
  98.  
  99. /* ******************** USER BODY ******************** */
  100.         {
  101.         BPTR lock;
  102.  
  103.         if (lock = Lock(argv.path, SHARED_LOCK)) {
  104.             struct FileInfoBlock *fib;
  105.             if (fib = AllocDosObject(DOS_FIB, NULL)) {
  106.             if (Examine (lock, fib)) {
  107.                 STRPTR det[] = {
  108.                 "ST_PIPEFILE", "ST_LINKFILE", "ST_FILE",
  109.                 "?",           "?",           "?",
  110.                 "ST_ROOT",     "ST_USERDIR",  "ST_SOFTLINK",
  111.                 "ST_LINKDIR"
  112.                 };
  113.                 UBYTE prot[] = "rwedrwed-sparwed";
  114.  
  115.                 {
  116.                 LONG i,p;
  117. #                define MAXMBIT 15
  118. #                define MINMBIT    4
  119. #                define MAXUBIT    3
  120. #                define MINUBIT    0
  121.                 p = fib->fib_Protection;
  122.                 for (i = MAXMBIT; i >= MINMBIT; -- i)
  123.                     if (!(p & (1 << i)))
  124.                     prot[MAXMBIT - i] = '-';
  125.                 for (i = MAXUBIT; i >= MINUBIT; -- i)
  126.                     if ((p & (1 << i)))
  127.                     prot[MAXMBIT - i] = '-';
  128.                 }
  129.  
  130.  
  131.                 Printf("DiskKey     = 0x%04lx;\n"
  132.                    "DirEntryType= %ld;   /* %s */\n"
  133.                    "FileName    = \"%s\";\n"
  134.                    "Protection  = \"%s\";\n"
  135.                    "EntryType   = %ld;   /* %s */\n"
  136.                    "Size        = %ld;\n"
  137.                    "NumBlocks   = %ld;\n"
  138.                    "Comment     = \"%s\";\n"
  139.                    "OwnerUID    = 0x%04lx;\n"
  140.                    "OwnerGID    = 0x%04lx;\n"
  141.                     ,
  142.                     fib->fib_DiskKey,
  143.                     fib->fib_DirEntryType, det[fib->fib_DirEntryType+5],
  144.                     fib->fib_FileName,
  145.                     /*fib->fib_Protection, */ prot,
  146.                     fib->fib_EntryType, det[fib->fib_EntryType+5],
  147.                     fib->fib_Size,
  148.                     fib->fib_NumBlocks,
  149.                     fib->fib_Comment,
  150.                     fib->fib_OwnerUID,
  151.                     fib->fib_OwnerGID,
  152.                     0);
  153.  
  154.             } /* if */
  155.             FreeDosObject(DOS_FIB, fib);
  156.             } /* if */
  157.             UnLock(lock);
  158.         } /* if */
  159.         }
  160. /* ******************** USER BODY ******************** */
  161.         FreeArgs (args);
  162.     } /* if */
  163.  
  164.     if (retval > RETURN_WARN)
  165.         PrintFault(IoErr(), "Examine");
  166.  
  167.     CloseLibrary (DOSBase);
  168.     } /* if */
  169.     return (retval);
  170. } /* _main */
  171.  
  172. /******************************************************************************
  173. *****  END Examine.c
  174. ******************************************************************************/
  175.  
  176.  
  177.